﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using HotelManagement.Class;

namespace HotelManagement
{
    public partial class UpdateHousekeepingScheduleMenu : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                displayScheduleIDAndDate();
            }
        }

        protected void btnUpdateSched_Click(object sender, EventArgs e)
        {
            try
            {

                Server.Transfer("UpdateHousekeepingSchedule.aspx?scheduleID=" + lbScheduleID.SelectedValue);
            }
            catch (Exception)
            {
                lblStatus.Text = "Please Select Staff ID to Search";
            }
        }

        protected void btnGoBack_Click(object sender, EventArgs e)
        {
            Server.Transfer("ManageHousekeepingAndStaff.aspx");
        }

        private void displayScheduleIDAndDate()
        {
            lbScheduleID.Items.Clear();
            string selectSQL = "SELECT scheduleID , DATENAME(day, ScheduleDate) as [Day], DATENAME(month, ScheduleDate) as [Month], DATENAME(year, ScheduleDate) as [Year] FROM HousekeepingSchedule";

            SqlDataReader reader;

            try
            {
                SqlConnection con = StaffDBManager.ConnectToDatabase();

                SqlCommand cmd = new SqlCommand(selectSQL, con);
                ListItem newItem = new ListItem();


                con.Open();
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    newItem = new ListItem();
                    newItem.Text = reader["scheduleID"].ToString() + " - " + reader["Day"].ToString() + " " + reader["Month"].ToString() + " " + reader["Year"].ToString();
                    newItem.Value = reader["scheduleID"].ToString();
                    lbScheduleID.Items.Add(newItem);
                }
                reader.Close();


            }
            catch (SqlException Ex1)
            {
                lblStatus.Text = "Error: " + Ex1 + "Please try again";
            }
        }


    }
}